package leetcode_301_400;

import java.net.IDN;
import java.util.Arrays;

public class LeeCode_322 {
    public static void main(String[] args) {
//        System.out.println(coinChange(new int[]{1, 2, 5}, 11));
//        System.out.println(coinChange(new int[]{1}, 0));
//        System.out.println(coinChange(new int[]{2, 3, 5}, 9));
//        System.out.println(coinChange(new int[]{3, 4, 7}, 13));
        System.out.println(coinChange(new int[]{186,419,83,408}, 6249));
    }

    private static int coinChange(int[] coins, int amount) {
        int max = amount + 1;
        int[] dp = new int[amount + 1];
        Arrays.fill(dp, max);
        dp[0] = 0;
        for (int i = 1; i <= amount; i++) {
            for (int coin : coins) {
                int index = i - coin;
                if (index >= 0) {
                    dp[i] = Math.min(dp[index] + 1, dp[i]);
                }
            }
        }
        return dp[amount] == max ? -1 : dp[amount];
    }
}
